#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include "TestSalesData.cpp"
using namespace std;
using namespace std::placeholders;
void elimDups(vector<string> &words);
void practice_10_11();
bool isShorter(const string &s1,const string &s2);
bool compareIsbn(const Sales_data &s1,const Sales_data &s2);
void practice_10_12();
bool isLongString(const string &s1);
void practice_10_13();
void example_p346();
void example_p347();
void example_p348();
void practice_10_14();
void practice_10_15();
void biggies(vector<string> &words,vector<string>::size_type sz);
void practice_10_16();
void practice_10_17();
void practice_10_20();
void practice_10_21();
bool count_size(const string &s,string::size_type sz);
void practice_10_22();
void practice_10_23();
int main()
{
	//practice_10_11();
	//practice_10_12();
	//practice_10_13();
	//example_p346();
	//example_p347();
	//example_p348();
	//practice_10_14();
	//practice_10_15();
	//practice_10_16();
	//practice_10_17();
	//practice_10_20();
	//practice_10_21();
	//practice_10_22();
	practice_10_23();
	return 0;
}
void elimDups(vector<string> &words)
{
	sort(words.begin(),words.end());
	auto end_unique=unique(words.begin(),words.end());
	words.erase(end_unique,words.end());
}
bool isShorter(const string &s1,const string &s2)
{
	return s1.size()<s2.size();
}
void practice_10_11()
{
	vector<string> words{"zyl1","fox","zyl1","the","zyl111ok","the","title","hoo"};
	elimDups(words);
	stable_sort(words.begin(),words.end(),isShorter);
	for(const auto &s:words)
		cout<<s<<" ";
}
bool compareIsbn(const Sales_data &s1,const Sales_data &s2)
{
	return s1.isbn().size()<s2.isbn().size();
}
void practice_10_12()
{
	Sales_data s1("zyl111ok");
	Sales_data s2("zyl");
	Sales_data s3("HelloWorld");
	Sales_data s4("bored");
	vector<Sales_data> v{s1,s2,s3,s4};
	sort(v.begin(),v.end(),compareIsbn);
	for(const auto &s:v)
		cout<<s.isbn()<<" ";
}
bool isLongString(const string &s1)
{
	return s1.size()>=5;
}
void practice_10_13()
{
	vector<string> words{"zyl1","fox","znmjopl","the","zyl111ok","afhqof","title","hoo"};
	partition(words.begin(),words.end(),isLongString);
	for(auto it=words.begin();it!=words.begin()+(words.size()/2);++it)
		cout<<*it<<" ";
}
void example_p346()
{
	auto f=[]()->int{return 42;};
	cout<<f()<<endl;
}
void example_p347()
{
	auto f=[](const string &a,const string &b){return a.size()>b.size();};
	cout<<f("zyl111ok","zyl")<<endl;
}
void example_p348()
{
	string::size_type sz=5;
	auto f=[sz](const string &s)->bool{return s.size()>=sz;};
	cout<<f("zyl111ok")<<endl;
}
void practice_10_14()
{
	int sum=0;
	auto f=[](const int &a,const int &b)->int{return a+b;};
	cout<<f(6,7)<<endl;
}
void practice_10_15()
{
	int a=5;
	auto f=[a](const int &b)->int{return a+b;};
	cout<<f(7)<<endl;
}
void biggies(vector<string> &words,vector<string>::size_type sz)
{
	elimDups(words);
	stable_sort(words.begin(),words.end(),[](const string &a,const string &b){return a.size()<b.size();});
	auto wc=find_if(words.begin(),words.end(),[sz](const string &a){return a.size()>=sz;});
	auto count=words.end()-wc;
	cout<<count<<endl;
	for_each(wc,words.end(),[](const string &s){cout<<s<<" ";});
	cout<<endl;
}
void practice_10_16()
{
	vector<string> words{"zyl1","fox","znmjopl","the","zyl111ok","afhqof","title","hoo"};
	biggies(words,5);
}
void practice_10_17()
{
	Sales_data s1("zyl111ok");
	Sales_data s2("zyl");
	Sales_data s3("HelloWorld");
	Sales_data s4("bored");
	vector<Sales_data> v{s1,s2,s3,s4};
	sort(v.begin(),v.end(),[](const Sales_data &s1,const Sales_data &s2)->bool{return s1.isbn().size()<s2.isbn().size();});
	for(const auto &s:v)
		cout<<s.isbn()<<" ";
}
void practice_10_20()
{
	string::size_type sz=6;
	vector<string> words{"zyl1","fox","znmjopl","the","zyl111ok","afhqof","title","hoo"};
	auto wc=count_if(words.begin(),words.end(),[sz](const string &a){return a.size()>=sz;});
	cout<<wc<<endl;
}
void practice_10_21()
{
	size_t v1=42;
	auto f=[v1]()mutable -> bool{return (--v1>0);};
	while(f());
}
bool count_size(const string &s,string::size_type sz)
{
	return s.size()>=sz;
}
void practice_10_22()
{
	vector<string> words{"zyl1","fox","znmjopl","the","zyl111ok","afhqof","title","hoo"};
	auto f=bind(count_size,_1,6);
	cout<<count_if(words.begin(),words.end(),f)<<endl;
}
void practice_10_23()
{
	vector<int> v{1,2,3,4,5,6,7,8,9,10,11,12};
	for(int i:v){
		auto f=bind(count_size,_1,i);
		if(!f("zyl111ok")){
			cout<<i<<endl;
			break;
		}
	}
}








